package com.project_doctor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project_doctor.pojo.Service;
import com.project_doctor.pojo.dto.ServiceDTO;
import com.project_doctor.service.ServiceService;
import com.project_doctor.mapper.ServiceMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* @author xixif
* @description 针对表【t_service(服务项目表)】的数据库操作Service实现
* @createDate 2025-06-16 16:39:18
*/
@org.springframework.stereotype.Service
public class ServiceServiceImpl extends ServiceImpl<ServiceMapper, Service>
    implements ServiceService{
    @Autowired
    private ServiceMapper serviceMapper;

    @Override
    public List<Service> getService() {
        LambdaQueryWrapper<Service> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(Service::getId, Service::getName);
        return serviceMapper.selectList(wrapper);
    }

    @Override
    public Page<Service> getServiceList(ServiceDTO queryDTO, Integer pageNum, Integer pageSize) {
        QueryWrapper<Service> lambda = new QueryWrapper<>();
        // 状态筛选
        if (StringUtils.isNotBlank(queryDTO.getType())) {
            lambda.eq("s.type", queryDTO.getType());
        }
        // 关键字搜索 (编号/名称/次数/原价/介绍)
        if (StringUtils.isNotBlank(queryDTO.getKeyword())) {
            lambda.and(w -> w
                    .like("s.id", queryDTO.getKeyword())
                    .or()
                    .like("s.name", queryDTO.getKeyword())
                    .or()
                    .like("times", queryDTO.getKeyword())
                    .or()
                    .like("price", queryDTO.getKeyword())
                    .or()
                    .like("description", queryDTO.getKeyword())
            );
        }
        Page<Service> page = new Page<>(pageNum,pageSize);
        return serviceMapper.selectPageService(page,lambda);
    }

    @Override
    public void deleteService(Integer id) {
        serviceMapper.deleteById(id);
    }

    @Override
    public Service getServiceById(Integer id) {
        return serviceMapper.selectById(id);
    }
}




